package club.kingyin.easycache.method;

import club.kingyin.easycache.component.InvokeHandler;

public class ProxyMethod implements InvokeHandler, InvokeExceptionHandler {

    private InvokeHandler currentMethod;
    private InvokeExceptionHandler exceptionHandler;

    public void setCurrentMethod(InvokeHandler currentMethod) {
        this.currentMethod = currentMethod;
    }

    public void setExceptionHandler(InvokeExceptionHandler exceptionHandler) {
        this.exceptionHandler = exceptionHandler;
    }

    @Override
    public boolean handler(Exception e) {
        return exceptionHandler.handler(e);
    }

    @Override
    public Object invoke() throws club.kingyin.easycache.exception.InvokeException {
        try {
            Object res = currentMethod.invoke();
            return res;
        } catch (Throwable e) {
            throw new club.kingyin.easycache.exception.InvokeException(e);
        }
    }
}
